//
//  CRSessionTimestampCell.m
//  TestPrj
//
//  Created by 朱铅峰 on 2020/9/28.
//  Copyright © 2020 Xing. All rights reserved.
//

#import "CRSessionTimestampCell.h"
#import "CRTimestampModel.h"
#import "UIImage+CRKit.h"
#import "CRKit.h"
#import "CRKitUtil.h"

@interface CRSessionTimestampCell()

@property (nonatomic,strong) CRTimestampModel *model;

@end

@implementation CRSessionTimestampCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [CRKit sharedKit].config.cellBackgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        _timeBGView = [[UIImageView alloc] initWithFrame:CGRectZero];
        [self addSubview:_timeBGView];
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _timeLabel.font = [UIFont boldSystemFontOfSize:10.f];
        _timeLabel.textColor = [UIColor whiteColor];
        [self addSubview:_timeLabel];
        [_timeBGView setImage:[[UIImage cr_imageInKit:@"icon_session_time_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(8,20,8,20) resizingMode:UIImageResizingModeStretch]];

    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    [_timeLabel sizeToFit];
    _timeLabel.center = CGPointMake(self.x, 20);
    _timeBGView.frame = CGRectMake(_timeLabel.left - 7, _timeLabel.top - 2, _timeLabel.width + 14, _timeLabel.height + 4);
}


- (void)refreshData:(CRTimestampModel *)data{
    self.model = data;
    if([self checkData]){
        CRTimestampModel *model = (CRTimestampModel *)data;
        [_timeLabel setText:[CRKitUtil showTime:model.messageTime showDetail:YES]];
    }
}

- (BOOL)checkData{
    return [self.model isKindOfClass:[CRTimestampModel class]];
}


@end
